package com.situ.company.score.service;

import java.util.List;

import com.situ.company.score.dao.ScoreDao;
import com.situ.company.score.model.ScoreModel;

public class ScoreService {

	private ScoreDao dao = new ScoreDao();

	// 返回类型的作用：为了在调用该方法后，通过返回结果，知道该方法调用过程中的执行情况
	/**
	 * 添加 添加的主键不存在时允许添加，否则不允许添加
	 * 
	 * @param model
	 * @return
	 */
	public String insert(ScoreModel model) {
		ScoreModel mdb = selectModel(model);
		if (mdb != null)
			return "E";
		Integer result = dao.insert(model);
		return String.valueOf(result);
	}

	/**
	 * 删除
	 * 
	 * @param id
	 * @return
	 */
	public String delete(int id) {
		Integer result = dao.delete(id);
		return String.valueOf(result);
	}

	/**
	 * 修改
	 * 
	 * @param model
	 * @return
	 */
	public String update(ScoreModel model) {
		Integer result = dao.update(model);
		return String.valueOf(result);
	}

	/**
	 * 多条件的模糊查询出一些记录
	 * 
	 * @param model
	 * @return
	 */
	public List<ScoreModel> selectList(ScoreModel model) {
		String codeEmp = model.getCodeEmp();
		if (codeEmp != null)
			model.setCodeEmp("%" + codeEmp + "%");
		String codePro = model.getCodePro();
		if (codePro != null)
			model.setCodePro("%" + codePro + "%");
		return dao.selectList(model);
	}

	/**
	 * 查询出唯一记录
	 * 
	 * @param model
	 * @return
	 */
	public ScoreModel selectModel(ScoreModel model) {
		ScoreModel temp = new ScoreModel();
		temp.setCodeEmp(model.getCodeEmp());
		List<ScoreModel> list = dao.selectList(temp);
		// if(FmtEmpty.isEmpty(list))
		if (list == null || list.isEmpty())
			return null;
		return list.get(0);
	}

	/**
	 * 根据id查询
	 * 
	 * @param model
	 * @return
	 */
	public ScoreModel selectId(ScoreModel model) {
		ScoreModel temp = new ScoreModel();
		temp.setId(model.getId());
		List<ScoreModel> list = dao.selectList(temp);
		// if(FmtEmpty.isEmpty(list))
		if (list == null || list.isEmpty())
			return null;
		return list.get(0);
	}

	/**
	 * 查询记录条数
	 * 
	 * @param model
	 * @return
	 */
	public int selectCount(ScoreModel model) {
		ScoreModel mdb = new ScoreModel();
		String codeEmp = model.getCodeEmp();
		mdb.setCodeEmp(codeEmp == null ? "%%" : "%" + codeEmp + "%");
		String codePro = model.getCodePro();
		mdb.setCodePro(codePro == null ? "%%" : "%" + codePro + "%");
		return dao.selectCount(mdb);
	}

}
